package com.googlecode.yoohoo.xmppcore.protocol.parsing;

import com.googlecode.yoohoo.utils.Utils;

public class ProtocolRelation {
	private ProtocolKey enclosing;
	private ProtocolKey embedded;
	
	public ProtocolRelation(ProtocolKey enclosing, ProtocolKey embedded) {
		this.enclosing = enclosing;
		this.embedded = embedded;
	}

	public ProtocolKey getEnclosing() {
		return enclosing;
	}

	public void setEnclosing(ProtocolKey enclosing) {
		this.enclosing = enclosing;
	}

	public ProtocolKey getEmbedded() {
		return embedded;
	}

	public void setEmbedded(ProtocolKey embedded) {
		this.embedded = embedded;
	}
	
	@Override
	public int hashCode() {
		return (enclosing == null ? 0 : enclosing.hashCode()) +
			(embedded == null ? 0 : embedded.hashCode());
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj instanceof ProtocolRelation) {
			ProtocolRelation other = (ProtocolRelation)obj;
			
			return Utils.equalsEvenNull(this.enclosing, other.enclosing) &&
				Utils.equalsEvenNull(this.embedded, other.embedded);
		}
		
		return false;
	}
}
